package com.lzj.servlet;

import com.lzj.dao.UserDao;
import com.lzj.dao.impl.UserDaoImpl;
import com.lzj.entity.Sku;
import com.lzj.service.UserService;
import com.lzj.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * <p>
 *
 * </p>
 *
 * @autor:lzj
 * @date:2021/12/5
 */
public class SkuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");//通过超链接将值传送过来
//        name=new String(name.getBytes("iso-8859-1"),"utf-8");
//        System.out.println(name);
        UserServiceImpl userService = new UserServiceImpl();
        UserDao userDao = new UserDaoImpl();
        userService.setUserDao(userDao);
        Sku sku = userService.querySku(Integer.valueOf(id));
        req.setAttribute("skuId",id);
        req.setAttribute("url",sku.getUrl());
        req.setAttribute("name",sku.getName());
        req.setAttribute("price",sku.getPrice());
        req.setAttribute("specification",sku.getSpecification());
        req.setAttribute("count",sku.getCount());
        req.getRequestDispatcher("/detail.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
